<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-form :model="listQuery" inline>
          <el-form-item label="日期范围">
            <el-date-picker
              v-model="listQuery.start_date"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择开始时间"
            >
            </el-date-picker>
            <el-date-picker
              v-model="listQuery.end_date"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择结束时间"
            >
            </el-date-picker>
          </el-form-item>
          <!-- <el-form-item label="用户等级">
            <el-select v-model="listQuery.grade" clearable placeholder="请选择用户等级">
              <el-option
                v-for="item in gradelist"
                :key="item.id"
                :label="item.grade"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item> -->
          <!-- <br /> -->
          <!-- <el-form-item label="用户昵称">
            <el-input
              v-model="listQuery.nickname"
              clearable
              placeholder="请输入用户昵称"
            ></el-input>
          </el-form-item>
          <el-form-item label="用户编号">
            <el-input
              v-model="listQuery.user_no"
              clearable
              placeholder="请输入用户编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input
              v-model="listQuery.mobile"
              clearable
              placeholder="请输入手机号"
            ></el-input>
          </el-form-item> -->
          <el-form-item>
            <el-button
              type="primary"
              @click="deBounceWrap(handleSubmit)"
              :loading="loading"
              >搜索
            </el-button>
            <el-button type="primary" @click="deBounceWrap(handleExcel)"
              >导出</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="center mb-4">
        <el-card id="box-card">
          <div slot="header" class="text item">平台总流水</div>
          <div>{{ serial_total }}<span class="coin">金币</span></div>
        </el-card>
        <el-card id="box-card">
          <div slot="header" class="text item">注册总人数</div>
          <div>{{ user_reg_total }}</div>
        </el-card>
        <el-card id="box-card">
          <div slot="header" class="text item">总充值</div>
          <div>{{ recharge_total }}</div>
        </el-card>
        <el-card id="box-card">
          <div slot="header" class="text item">用户成功提现金额</div>
          {{ withdraw_total }}
        </el-card>
        <el-card id="box-card">
          <div slot="header" class="text item">财务打款金额</div>
          {{ withdraw_total_audit }}
        </el-card>
        <el-card id="box-card">
          <div slot="header" class="text item">用户待审核提现金额</div>
          {{ withdraw_check_total }}
        </el-card>
      </div>
      <el-table :data="tableData" border>
        <el-table-column label="日期" prop="date"></el-table-column>
        <el-table-column
          label="充值金额"
          prop="recharge_money"
        ></el-table-column>
        <el-table-column
          label="用户成功提现金额"
          prop="withdraw_money"
        ></el-table-column>
        <el-table-column
          label="财务打款金额"
          prop="withdraw_money_audit"
        ></el-table-column>
        <el-table-column
          label="待审核提现金额"
          prop="withdraw_money_check"
        ></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
import { statistic, userGradeExport } from "@/api/order/dataStatistics";

export default {
  data() {
    return {
      listQuery: {
        start_date: undefined,
        end_date: undefined,
        nickname: undefined,
        user_no: undefined,
        mobile: undefined,
        grade: undefined
      },
      gradelist: [],
      serial_total: undefined,
      user_reg_total: undefined,
      recharge_total: undefined,
      withdraw_total: undefined,
      withdraw_total_audit: undefined,
      withdraw_check_total: "",
      tableData: [],
      loading: false
    };
  },
  created() {
    this.getStatistic();
  },
  methods: {
    getStatistic() {
      let data = {};
      for (let key in this.listQuery) {
        if (this.listQuery[key]) {
          data[key] = this.listQuery[key];
        }
      }
      statistic(data).then(res => {
        this.tableData = res.data.everyday_recharge_total;
        this.serial_total = res.data.serial_total;
        this.user_reg_total = res.data.user_reg_total;
        this.recharge_total = res.data.recharge_total;
        this.withdraw_total = res.data.withdraw_total;
        this.withdraw_total_audit = res.data.withdraw_total_audit;
        this.withdraw_check_total = res.data.withdraw_check_total;
        this.gradelist = res.data.grades;
        this.listQuery.grade = res.data.grades && res.data.grades.grade;
      });
    },
    handleSubmit() {
      if (this.listQuery.start_date > this.listQuery.end_date) {
        this.$message.warning("请选择正确的日期范围");
        return;
      }
      this.getStatistic();
    },
    handleExcel() {
      let data = {
        start_date: this.listQuery.start_date,
        end_date: this.listQuery.end_date,
        grade: this.listQuery.grade
      };
      userGradeExport(data).then(res => {
        location.href = res.data.download_url;
      });
    }
  }
};
</script>
<style scoped>
.text {
  font-size: 14px;
}

.item {
  padding: 0;
}

#box-card {
  width: 480px;
  margin: 0 4px;
}

.center {
  display: flex;
  flex-direction: row;
}

.coin {
  font-size: 12px;
  background: rgb(28, 138, 241);
  color: #fff;
  width: 30px;
  margin-left: 5px;
  display: inline-block;
  text-align: center;
}
</style>
